<?php
namespace app\api\controller\m2979\auto;

use think\Db;
use service\ApiReturn;
use app\api\controller\Base;
use app\member\service\MemberCache;


class Freeyonghu extends Base {
                
/**
 *  查询用户
 *@create_time  2023-12-19 17:56:20
 */ 
public function get_yonghu($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];
  
    $order = 'freeyonghu.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freeyonghu.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freeyonghu.is_del', '=', 0]; 
 	$condition_str = ''; 
 	if (!empty($data['search_name'])) {
		$condition_str .= " freeyonghu.cheng LIKE '%{$data['search_name']}%' ||"; 
 	}
	if (!empty($data['search_name'])) {
		$condition_str .= " freeyonghu.jianjie LIKE '%{$data['search_name']}%' ||"; 
 	}
	$condition_str = trim($condition_str, '&&') ; 
 	$condition_str = trim($condition_str, '||') ; 
 	$condition_str = str_replace('&&' ,' and ' , $condition_str) ; 
 	$condition_str = str_replace('||' ,' or ' , $condition_str) ; 

    $select_info = array (
  'aihao' => 
  array (
    1 => '唱',
    2 => '跳',
    3 => 'rap',
    4 => '篮球',
  ),
  'xingbie' => 
  array (
    1 => '男',
    2 => '女',
    3 => '保密',
  ),
'member_user' => MemberCache::getUserListToMemberID(MemberID), 
); 
	$dataList = Db::table('lb_free_yonghu')
		->alias('freeyonghu')
		->leftjoin('lb_free_ceshiliebiao freeceshiliebiao', 'freeceshiliebiao.aid = freeyonghu.freeceshiliebiao_id')
		->leftjoin('lb_free_fenlei freefenlei', 'freefenlei.aid = freeyonghu.freefenlei_id')
		->leftjoin('lb_free_huiyuan freehuiyuan', 'freehuiyuan.aid = freeyonghu.freehuiyuan_id')
		->field("freeyonghu.aid,freeyonghu.mima1,freeyonghu.cheng,freeyonghu.jianjie,freeyonghu.free_field_121676,freeceshiliebiao.xingming as freeceshiliebiao_xingming,freeyonghu.jujueyuanyin,freeyonghu.fukuan,freeyonghu.tuikuan,freeyonghu.free_field_121631,freehuiyuan.dingdanjine as freehuiyuan_dingdanjine,freeyonghu.shengchanriqi,freeyonghu.qianming,freefenlei.yinpin as freefenlei_yinpin,freefenlei.shipin as freefenlei_shipin,freeyonghu.shuzi,freeyonghu.zonghe,freeyonghu.mima,freeyonghu.kaishishijian,freeyonghu.jisuanshijian,freeyonghu.duojiduoxuan,freeyonghu.duojidanxuan,freeyonghu.ceshi,freeyonghu.duoxuanxiang,freeyonghu.nianling,freeyonghu.lianjie,freeyonghu.yanse,freeyonghu.shoujihao,freeyonghu.xitongyuangong,freeyonghu.yinpin,freeyonghu.dituxuandian,freeyonghu.bianhao,freeyonghu.kaiguan,freeyonghu.shipin,freeyonghu.dantu,freeyonghu.tupian,freeyonghu.shijian,freeyonghu.wenjian,freeyonghu.aihao,freeyonghu.shengshiqu,freeyonghu.xingbie,freeyonghu.dizhi,freeyonghu.create_time,freeyonghu.status,freeyonghu.is_del")
		->where($where)
		->where($condition_str)
		->order($order)
		->find();
	if ($dataList){
		$infodataList = $dataList;
			$infodataList['freefenlei_yinpin']  = get_file_url($infodataList['freefenlei_yinpin']);
			$infodataList['freefenlei_shipin']  = [get_file_url($infodataList['freefenlei_shipin'])];
			$infodataList['kaishishijian'] = $infodataList['kaishishijian']? date('Y-m-d H:i:s', $infodataList['kaishishijian']): '';
			$infodataList['ceshi'] = $infodataList['ceshi']? date('Y', $infodataList['ceshi']): '';
			$infodataList['nianling'] = $infodataList['nianling']? date('Y', $infodataList['nianling']): '';
			$infodataList['xitongyuangong_name'] = $select_info['member_user']["{$infodataList['xitongyuangong']}"] ?? '';
			$infodataList['yinpin']  = get_file_url($infodataList['yinpin']);
			$infodataList['shipin']  = [get_file_url($infodataList['shipin'])];
			$infodataList['dantu']  = get_file_url($infodataList['dantu']);
			$infodataList['tupian'] = get_files_url($infodataList['tupian']);
			$infodataList['shijian'] = $infodataList['shijian']? date('Y-m-d H:i:s', $infodataList['shijian']): '';
			$infodataList['wenjian'] = get_pass_files_url($infodataList['wenjian'],1);
			$infodataList['aihao_name'] = $select_info['aihao']["{$infodataList['aihao']}"] ?? '';
		$area = \app\common\model\Area::where([["region_code", "in", $infodataList['shengshiqu']]])->column("name");
		if (count($area) > 0) {
			$infodataList['shengshiqu_area'] = implode(',', $area);
		}else{
			$infodataList['shengshiqu_area'] = '';
		}
			$infodataList['xingbie_name'] = $select_info['xingbie']["{$infodataList['xingbie']}"] ?? '';
			$infodataList['create_time'] = $infodataList['create_time'];
		$dataList = $infodataList;
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}

}